var App = require('app');
var GlobalShortcut = require('global-shortcut');
var BrowserWindow = require('browser-window');

var __dirname = __dirname;
var window = null;

App.on('window-all-closed', function () {
    App.quit()
})

App.on('ready', function () {
    createWindow();
    window.show();
    setGlobalShortcuts();
});

function createWindow() {
    window = new BrowserWindow({
        resizable: true,
        frame: true,
        width: 1024,
        height: 768,
        'auto-hide-menu-bar': true,
        'use-content-size': true,
        'web-preferences': {
            // 'node-integration': false,
            'web-security': false,
            'allow-displaying-insecure-content': true,
            'allow-running-insecure-content': true
        },
        show: false
    });
    window.on('closed', function (evernt) {
        window = null;
    });
    window.webContents.on('did-finish-load', function () {
        window.maximize();
        window.webContents.openDevTools();
    });
    window.loadUrl('file://' + __dirname + '/app/fileman.html');
}

function setGlobalShortcuts() {
    GlobalShortcut.unregisterAll();
    GlobalShortcut.register('CmdOrCtrl + R', function () {
        window.reload();
    });
}
